﻿@model HanGu.Entity.MemberInfo
@{
    Layout = null;
    TempData["TitlePic"] = Model.PicPath;
    TempData["ContorlID"] = "Introduction";
    TempData["Remark"] = Model.Introduction;
    TempData["GropName"] = Model.GUID;
    var SexList = ViewData["SexList"] as SelectList;
    var IsMarryList = ViewData["IsMarry"] as SelectList;
    var ProviceList = ViewData["Provice"] as SelectList;
    var CityList = ViewData["City"] as SelectList;
    var NativePlaceList = ViewData["NativePlace"] as SelectList;
    var JobList = ViewData["Job"] as SelectList;
    var JobSelected = new List<string>();
    if (Model.Job != null)
    {
        JobSelected.AddRange(Model.Job.Split(','));
    }
    var TradeList = ViewData["Trade"] as SelectList;
    var TradeSelected = new List<string>();
    if (Model.Trade != null)
    {
        TradeSelected.AddRange(Model.Trade.Split(','));
    }
    var Position = ViewData["Position"] as SelectList;
    var PositionSelected = new List<string>();
    if (Model.Position != null)
    {
        PositionSelected.AddRange(Model.Position.Split(','));
    }

    var InterestList = ViewData["Interest"] as SelectList;
    List<string> InterestArry = new List<string>();
    if (Model.Interest != null)
    { InterestArry.AddRange(Model.Interest.Split(',')); }

    var MemberGrade = ViewData["MemberGrade"] as SelectList;
    var Degree = ViewData["Degree"] as SelectList;
    var Oganization = ViewData["Oganization"] as SelectList;
    var Groups = ViewData["Groups"] as SelectList;
    var GroupsSelected = ViewData["MemberGroups"] as List<string> ?? new List<string>();

    var Parents = ViewData["Parents"] as SelectList;
    Model.MemberAssigneds = Model.MemberAssigneds ?? new List<HanGu.Entity.MemberAssigned>();
    var SelectedParents = Model.MemberAssigneds.Select(c => c.ManagerID.ToString()).ToList<string>();
    string selectedParentsstr = string.Join(",", SelectedParents);
    var ImportantLevels = ViewData["ImportantLevel"] as SelectList;

    bool isQueryCharge = false;
    var CurentUser = Session["CurentUser"] as HanGu.Entity.CurrentUserDTO;
    isQueryCharge = CurentUser != null && CurentUser.Roles.SingleOrDefault(c => c.ID == "CustomerInfo_11") != null;
   
}
<script>
        function SelectJobOther(value,obj) {            
            if (value.indexOf("9999") > 0)
            {  $("#@ViewData["CurrentController"]Form #"+obj).show();}
            else
            { $("#@ViewData["CurrentController"]Form #"+obj).hide(); }
        }        
        $(document).ready(function(){
        SelectJobOther("","JobOther");
        SelectJobOther("","TradeOther");
        $("#@ViewData["CurrentController"]Form #Degree").val("@Model.Degree");
        $("#@ViewData["CurrentController"]Form #Grade").val("@Model.Grade");
        $("#@ViewData["CurrentController"]Form #Sex").val('@(Model.Sex ?? "sex_2")');
        $("#@ViewData["CurrentController"]Form #IsMarry").val('@(Model.IsMarry ?? "marry_2")');
        $("#@ViewData["CurrentController"]Form #Provice").val("@Model.Provice");
        $("#@ViewData["CurrentController"]Form #City").val("@Model.City");
        $("#@ViewData["CurrentController"]Form #NativePlace").val("@Model.NativePlace");
        $("#@ViewData["CurrentController"]Form #GroupID").val("@Model.GroupID");
        $("#@ViewData["CurrentController"]Form #Oganization").val("@Model.Oganization");
        $("#@ViewData["CurrentController"]Form #ImportantLevel").val("@Model.ImportantLevel");
        
        $(".AutoComplete").AutoComplete({
        'data': @MvcHtmlString.Create(ViewData["AutoOganization"] != null ? ViewData["AutoOganization"] as string : "[]")
        , 'width': 'auto'
            });

        });
        
         $(function () {
                        var validate={ 
                                        rules: {},
                                        messages: {}       
                                       };
                        validate.rules["Tel"]= {
                                                 remote: {
                                                            type: "POST",
                                                            url: "CustomerInfo/Default/TelExitsed/@Model.ID", 
                                                            data: {
                                                                    Tel: function () { return $(".TelExitsed").val(); }
                                                                    ,ID:'@Model.ID'
                                                                    }
                                                        }
                                                };
                        validate.messages["Tel"]={ remote: jQuery.format("手机号码已被注册") };
                        $("#@ViewData["CurrentController"]Form").validate(validate);
        });
       
//       function CheckForm()
//       {
//        var isValidate=$("#@ViewData["CurrentController"]Form").validate().form(); 
//       
//        if(!isValidate){ 
//          var $this = $("#memberinfocontent");
//           alert(isValidate);     
//            var options = {};
//            options.currentIndex = 0;// $this.attr("currentIndex") || 0;
//            options.eventType = $this.attr("eventType") || "click";
//            $this.tabs(options);
//        }       
//       }
</script>
<div class="pageContent">
    <form method="post" id="@ViewData["CurrentController"]Form" action="/CustomerInfo/Default/create?OpID=@ViewData["OperateID"]" enctype="MULTIPART/FORM-DATA" class="pageForm required-validate"
    onsubmit="return iframeCallback(this, navTabAjaxDone);">
    @Html.ValidationSummary(true)
    <div class="tabs" currentindex="0" eventtype="click" id="memberinfocontent">
        <div class="tabsHeader">
            <div class="tabsHeaderContent">
                <ul>
                    <li><a href="javascript:;"><span>客户基本信息</span></a></li>
                    <li><a href="/CustomerInfo/MemberChildren/index/@Model.ID" class="j-ajax"><span>子女信息</span></a></li>
                    <li><a href="/CustomerInfo/MemberContract/index/@Model.ID" class="j-ajax"><span>合同信息</span></a></li>
                    <li><a href="/CustomerInfo/MemberContact/index/@Model.ID" class="j-ajax"><span>联系记录</span></a></li>
                    @if (isQueryCharge)
                    {
                    <li><a href="/CustomerInfo/ChangeChargeRecorde/index/@Model.ID" class="j-ajax"><span>
                        积分记录</span></a></li>
                    }
                    <li><a href="javascript:;"><span>用户记录</span></a></li>
                </ul>
            </div>
        </div>
        <div class="tabsContent">
            <div class="pageFormContent" layouth="92">
                @Html.HiddenFor(model => model.ID)
                @Html.HiddenFor(model => model.GUID)
                @Html.HiddenFor(model => model.Pwd)
                @Html.HiddenFor(model => model.CreateTime)
                @Html.HiddenFor(model => model.Creator)
                @Html.HiddenFor(model => model.Updater)
                @Html.HiddenFor(model => model.UpdateTime)
                @Html.HiddenFor(model => model.Charge)
                @Html.Hidden("OldParents", selectedParentsstr)
                <div class="container">
                    <div class="title">
                        基本信息</div>
                    <div class="CreateDiv">
                        <div class="LeftDiv">
                            @* <p>
                    <label>
                        账号：</label>
                    @Html.TextBoxFor(model => model.UserName, new { @class = "required" })
                    @Html.ValidationMessageFor(model => model.UserName)
                </p>*@
                            <p>
                                <label>
                                    是否加入黑名单：</label>
                                @Html.CheckBox("IsBacklist", Model.IsBacklist)
                                @Html.ValidationMessageFor(model => model.IsBacklist)
                            </p>
                            @* <p>
                                <label>
                                    积分：</label>
                                @Html.TextBoxFor(model => model.Charge, new { @Readonly = "Readonly" })
                                @Html.ValidationMessageFor(model => model.Charge)
                            </p>*@
                            <p>
                                <label>
                                    姓名：</label>
                                @Html.TextBoxFor(model => model.RealName, new { @class = "required" })
                                @Html.ValidationMessageFor(model => model.RealName)
                            </p>
                            <p>
                                <label>
                                    性别：</label>
                                @Html.DropDownListFor(model => model.Sex, SexList, new { @class = "combox required" })
                                @Html.ValidationMessageFor(model => model.Sex)
                            </p>
                            <p>
                                <label>
                                    出生日期：</label>
                                @Html.TextBoxFor(model => model.Birthday, new { @class = "date", format = "yyyy-MM-dd", yearstart = "-100", yearend = "0", @readonly = "true" })
                                @Html.ValidationMessageFor(model => model.Birthday)
                            </p>
                            <p>
                                <label>
                                    婚姻状况：</label>
                                @Html.DropDownListFor(model => model.IsMarry, IsMarryList, new { @class = "combox" })
                                @Html.ValidationMessageFor(model => model.IsMarry)
                            </p>
                            <p>
                                <label>
                                    证件号码：</label>
                                @Html.TextBoxFor(model => model.CredentialNum, new { @class = "" })
                                @Html.ValidationMessageFor(model => model.CredentialNum)
                            </p>
                            <p>
                                <label>
                                    所在城市：</label>
                                @Html.DropDownListFor(model => model.Provice, ProviceList,HanGu.CRM.HelperCommon.SelectDefaultValue, new { @class = "combox", @ref = "City", @refUrl = "/Area/GetCitys/{value}" })
                              
                                @Html.DropDownListFor(model => model.City, CityList, HanGu.CRM.HelperCommon.SelectDefaultValue, new { @class = "combox" })
                            </p>
                            <p>
                                <label>
                                    通讯地址：</label>
                                @Html.TextBoxFor(model => model.Address, new { @class = "" })
                                @Html.ValidationMessageFor(model => model.Address)
                            </p>
                            <p>
                                <label>
                                    邮编：</label>
                                @Html.TextBoxFor(model => model.Zip, new { @class = "" })
                                @Html.ValidationMessageFor(model => model.Zip)
                            </p>
                            <p>
                                <label>
                                    籍贯：</label>
                                @Html.DropDownListFor(model => model.NativePlace, NativePlaceList, HanGu.CRM.HelperCommon.SelectDefaultValue, new { @class = "combox" })
                                @Html.ValidationMessageFor(model => model.NativePlace)
                            </p>
                            @*<p style="height: 70px">
                    <label>
                        关联会员：</label>
                    @Html.TextAreaFor(model => model.RelationMem, new { @class = "", cols = "18", rows = "3" })
                    @Html.ValidationMessageFor(model => model.RelationMem)
                </p>*@
                        </div>
                        <div class="rightDiv">
                            @* <p>
                                <label>
                                    标题图片：</label>
                                @Html.HiddenFor(c => c.PicPath)
                                @Html.Partial("uploadify")
                            </p>*@ @*<p>
                                <label>
                                    工作单位：</label>
                                @Html.TextBoxFor(model => model.WorkAddress, new { @class = "" })
                                @Html.ValidationMessageFor(model => model.WorkAddress)
                            </p>*@
                            <div style="height:100%">
                                <label>
                                    所属行业：</label>
                                    <table><tr>
                                    @{int j = 1;}
                                @foreach (var item in TradeList)
                                {
                                    <td nowarp="nowarp">
                                    <input name="Trade" class="checkbox" id="Trade" style="magin-left: 5px;" type="checkbox" CHECKED="@TradeSelected.Contains(item.Value)" value="@item.Value"/>
                                    @item.Text
                                              @if (j % 2 == 0)
                                              { 
                                                  @MvcHtmlString.Create("</tr><tr>")
                                              }
                                              @{j += 1;
                                }
                                     </td>
                                }
                                </tr></table>
                                @Html.ValidationMessageFor(model => model.Trade)
                            </div>
                             <div class="divider"></div>
                            <p style="width:500px;height:100%">
                                <label for="Oganization">
                                    所属于组织：</label>
                                @*  <label style="padding-left:0;">
                                @Html.DropDownListFor(model => model.Oganization, Oganization, new { @class = "EditSelect", name = "Oganization" })</label> *@
                                @Html.TextBoxFor(model => model.Oganization, new { @Class = "AutoComplete" })
                                @Html.ValidationMessageFor(model => model.Oganization)
                            </p>
                            <div class="divider"></div>
                            <div style="height:100%">
                                <label>
                                    职位：</label>
                               
                                 <table><tr>
                                    @{ j = 1;}
                                @foreach (var item in Position)
                                {
                                    <td nowarp="nowarp">
                                    <input name="Position" class="checkbox" id="Position" style="magin-left: 5px;" type="checkbox" CHECKED="@PositionSelected.Contains(item.Value)" value="@item.Value"/>
                                    @item.Text
                                              @if (j % 2 == 0)
                                              { 
                                                  @MvcHtmlString.Create("</tr><tr>")
                                              }
                                              @{j += 1;
                                }
                                     </td>
                                }
                                </tr></table>
                                @Html.ValidationMessageFor(model => model.Position)
                            </div>
                             <div class="divider"></div>
                             <div style="height:100%">
                                <label>
                                    职业：</label>                               
                                  <table><tr>
                                    @{ j = 1;}
                                @foreach (var item in JobList)
                                {
                                    <td nowarp="nowarp">
                                    <input name="Job" class="checkbox" id="Job" style="magin-left: 5px;" type="checkbox" CHECKED="@JobSelected.Contains(item.Value)" value="@item.Value"/>
                                    @item.Text
                                              @if (j % 2 == 0)
                                              { 
                                                  @MvcHtmlString.Create("</tr><tr>")
                                              }
                                              @{j += 1;
                                }
                                     </td>
                                }
                                </tr></table>
                                @Html.ValidationMessageFor(model => model.Job)
                            </div>
                            <div class="divider"></div>
                             <div style="height:100%">
                                <label>
                                    兴趣点：</label>                               
                                  <table><tr>
                                    @{ j = 1;}
                                @foreach (var item in InterestList)
                                {
                                    <td nowarp="nowarp">
                                    <input name="Interest" class="checkbox" id="Interest" style="magin-left: 5px;" type="checkbox" CHECKED="@InterestArry.Contains(item.Value)" value="@item.Value"/>
                                    @item.Text
                                              @if (j % 2 == 0)
                                              { 
                                                  @MvcHtmlString.Create("</tr><tr>")
                                              }
                                              @{j += 1;
                                }
                                     </td>
                                }
                                </tr></table>
                                @Html.ValidationMessageFor(model => model.Interest)
                            </div>
                            @* <p>
                                <label>
                                    创建时间：</label>
                                @Html.TextBoxFor(model => model.CreateTime, new { @Readonly = "true" })
                                @Html.ValidationMessageFor(model => model.CreateTime)
                            </p>
                            <p>
                                <label>
                                    创建者：</label>
                                @Html.TextBoxFor(model => model.Creator, new { @Readonly = "true" })
                                @Html.ValidationMessageFor(model => model.Creator)
                            </p>
                            <p>
                                <label>
                                    修改时间：</label>
                                @Html.TextBoxFor(model => model.UpdateTime, new { @Readonly = "Readonly" })
                                @Html.ValidationMessageFor(model => model.UpdateTime)
                            </p>
                            <p>
                                <label>
                                    修改者：</label>
                                @Html.TextBoxFor(model => model.Updater, new { @Readonly = "Readonly" })
                                @Html.ValidationMessageFor(model => model.Updater)
                            </p>*@
                        </div>
                    </div>
                </div>
                <div class="container">
                    <div class="title">
                        允许联系方式</div>
                    <div class="CreateDiv">
                        <div class="LeftDiv">
                            <p>
                                <label>
                                    手机：</label>
                                @Html.TextBoxFor(model => model.Tel, new { @class = "Tel required TelExitsed" })
                                @Html.ValidationMessageFor(model => model.Tel)
                            </p>
                            <p>
                                <label>
                                    联系电话：</label>
                                @Html.TextBoxFor(model => model.Telephone, new { @class = "Telephone" })
                                @Html.ValidationMessageFor(model => model.Telephone)
                            </p>
                            <p>
                                <label>
                                    是否电话联系：</label>
                                @Html.CheckBoxFor(model => model.NoTel, new { @class = "CNoTel", target = "Telephone,Tel" })
                                @Html.ValidationMessageFor(model => model.NoTel)
                            </p>
                            <p>
                                <label>
                                    是否接收短信：</label>
                                @Html.CheckBoxFor(model => model.NoSMS, new { @class = "CNoSMS", target = ".TelExitsed" })
                                @Html.ValidationMessageFor(model => model.NoSMS)
                            </p>
                        </div>
                        <div class="rightDiv">
                            <p>
                                <label>
                                    邮箱：</label>
                                @Html.TextBoxFor(model => model.Email, new { @class = "email" })
                                @Html.ValidationMessageFor(model => model.Email)
                            </p>
                            <p>
                                <label>
                                    是否接收邮件：</label>
                                @Html.CheckBoxFor(model => model.NoEmail, new { @class = "CNoEmail", @target = "Email" })
                                @Html.ValidationMessageFor(model => model.NoEmail)
                            </p>
                            <p>
                                <label>
                                    即时联系方式：</label>
                                @Html.TextBoxFor(model => model.QLink, new { @class = "" })
                                @Html.ValidationMessageFor(model => model.QLink)
                            </p>
                        </div>
                    </div>
                </div>
                <div class="container">
                    <div class="title">
                        等级信息</div>
                    <div class="CreateDiv">
                        <div class="LeftDiv">
                            <p>
                                <label>
                                    学位：</label>
                                @Html.DropDownListFor(model => model.Degree, Degree, "无", new { @class = "combox" })
                                @Html.ValidationMessageFor(model => model.Degree)
                            </p>
                            <p>
                                <label>
                                    级别：</label>
                                @Html.DropDownListFor(model => model.Grade, MemberGrade, "无", new { @class = "combox" })
                                @Html.ValidationMessageFor(model => model.Grade)
                            </p>
                        </div>
                        <div class="rightDiv">
                            <p>
                                <label>
                                    重要级别：</label>
                                <label style="padding-left: 0;">
                                    @Html.DropDownListFor(model => model.ImportantLevel, ImportantLevels, new { @class = "required combox" })
                                    @Html.ValidationMessageFor(model => model.ImportantLevel)
                                </label>
                            </p>
                            <p style="width: 100%">
                                <label>
                                    新客户：</label>
                                @Html.CheckBoxFor(model => model.IsNew)
                                @Html.ValidationMessageFor(model => model.IsNew)
                            </p>
                            @* <p>
                                <label>
                                    是否直属：</label>
                                @Html.CheckBoxFor(model => model.IsDirectly)
                                @Html.ValidationMessageFor(model => model.IsDirectly)
                            </p>*@
                        </div>
                    </div>
                </div>
                <div>
                    <p style="width: 100%">
                        <label>
                            群：</label>
                        @foreach (var item in Groups)
                        {

                            <input name="memberGroups" class="checkbox" id="memberGroups" style="magin-left: 5px;" type="checkbox" CHECKED="@GroupsSelected.Contains(item.Value)" value="@item.Value"/>
                            @item.Text;

                        }
                        @Html.ValidationMessageFor(model => model.GroupID)
                    </p>
                </div>
                <div class="divider">
                </div>
                <div>
                    <label>
                        归属用户(<span style="color: red">*必填</span>)： <span style="display: none">
                            <input name="AssignedIns" class="" id="AssignedIns" style="magin-left: 5px;" type="checkbox" />
                        </span>
                    </label>
                    @foreach (var item in Parents)
                    {

                        <label style="width: auto; white-space: nowrap">
                            <input name="AssignedIns" class="checkbox required" id="AssignedIns" style="magin-left: 5px;" type="checkbox" value="@item.Value" checked="@SelectedParents.Contains(item.Value)"/>
                            @item.Text
                        </label>
                    }
                </div>
                <div>
                    <p style="width: 90%; height: 220px">
                        <label>
                            简介：</label>
                        @Html.TextAreaFor(model => model.Introduction, new { @class = "TextArea", cols = "100", rows = "10" })
                        @Html.ValidationMessageFor(model => model.Introduction)
                    </p>
                </div>
            </div>
            <div layouth="70" id="CustomerInfoMemberChildren" ref="/CustomerInfo/MemberChildren/index/@Model.ID">
            </div>
            <div layouth="70" id="CustomerInfoMemberContract" ref="/CustomerInfo/MemberContract/index/@Model.ID">
            </div>
            <div layouth="70" id="CustomerInfoMemberContact" ref="/CustomerInfo/MemberContact/index/@Model.ID">
            </div>
             @if (isQueryCharge)
             {
            <div layouth="70" id="CustomerInfoChangeChargeRecorde" ref="/CustomerInfo/ChangeChargeRecorde/index/@Model.ID">
            </div>
             }
            <div layouth="70">
                <table class="list" width="100%">
                    <thead>
                        <tr>
                            <th>
                                序号
                            </th>
                            <th>
                                用户名
                            </th>
                            <th>
                                时间
                            </th>
                        </tr>
                    </thead>
                    @{var i = 1;
                      Model.MemberAssignedHis = Model.MemberAssignedHis ?? new List<HanGu.Entity.vwMemberAssignedHis>();
                    }
                    @foreach (var item in Model.MemberAssignedHis)
                    {
                        <tr>
                            <td>
                                @i
                            </td>
                            <td>
                                @item.ManagerName@item.User
                            </td>
                            <td>
                                <span formatdate="yyyy-MM-dd HH:mm">@item.CreateDate</span>
                            </td>
                        </tr>
                        i += 1;
                    }
                </table>
            </div>
        </div>
    </div>
    <div class="formBar">
        <ul>
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="submit">
                            提交</button></div>
                </div>
            </li>
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" class="close">
                            取消</button></div>
                </div>
            </li>
        </ul>
    </div>
    </form>
    <script>
        (function ($) {
            $.validator.addMethod("CNoTel", function (value, element) {
                $this = $(element);
                var result = false;
                var targets = $this.attr("target").split(',');
                $.each(targets, function (i, v) {
                    if ($("." + v).val().length > 0) { result = true; }
                });
                return this.optional(element) || result;
            }, "手机或电话至少输入一项！");

            $.validator.addMethod("CNoSMS", function (value, element) {
                $this = $(element);
                var result = false;
                var targets = $($this.attr("target"));
                var val = targets.val();
                result = val != null && val.length > 0;
                return this.optional(element) || result;
            }, "请输入手机！");

            $.validator.addMethod("CNoEmail", function (value, element) {
                $this = $(element);
                var result = false;
                var targets = $("#" + $this.attr("target"));
                var val = targets.val();
                result = val != null && val.length > 0;
                return this.optional(element) || result;
            }, "请输入邮箱！");

            $.validator.addClassRules({
                CNoTel: { CNoTel: true },
                CNoSMS: { CNoSMS: true },
                CNoEmail: { CNoEmail: true }
            });

        })(jQuery);
    </script>
</div>
